/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ttfsserver;

import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Hashtable;
import pojo.POJOMyInfo;
import myutil.XMLHelper;

/**
 *
 * @author Tidus Le
 */
public class clsXMLMyInfo
{
    /**
     * Đọc thông tin của client từ file xml
     */
    public static void readMyInfo(POJOMyInfo myInfo)
    {
        ArrayList<Hashtable<String,String>> arrElements=XMLHelper.read("MyInfo");
        
        for(Hashtable<String,String> element:arrElements)
        {
            Enumeration e=element.keys();
              while(e.hasMoreElements())
              {
                  String key=(String)e.nextElement();
                  if(key.equals("myport")==true)
                    myInfo.setPort(element.get(key));
              }
        }
    }
    
    /**
     * Ghi thông tin vào file xml
     * @param myInfo 
     */
    public static void writeMyInfo(POJOMyInfo myInfo)
    {
        ArrayList<Hashtable<String,String>> arrElements=new ArrayList<Hashtable<String, String>>();
        
        Hashtable<String,String> element=new Hashtable<String, String>();
        element.put("myport", myInfo.getPort());
        arrElements.add(element);
        
        XMLHelper.write("MyInfo", arrElements);
    }
}
